package com.thememaker.util;

import com.jfoenix.svg.SVGGlyph;
import com.jfoenix.svg.SVGGlyphLoader;
import com.thememake.util.FileUtils;
import javafx.scene.paint.Paint;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class SVGLoadUtils {
    private static SVGLoadUtils svgLoadUtils;

    private SVGLoadUtils() {

    }

    public static SVGLoadUtils getInstance() {
        if (svgLoadUtils == null) {
            svgLoadUtils = new SVGLoadUtils();
            initSVGGlyph();
        }
        return svgLoadUtils;
    }

    private static void initSVGGlyph() {
        try {
            File resIcomoon = FileUtils.getResFile("/fonts/icomoon.svg");
            if (!resIcomoon.exists()) {
                resIcomoon = new File(FileUtils.getUserDirResPath(File.separator + "res" + File.separator + "fonts" + File.separator + "icomoon.svg"));
            }
//            File icomoon = new File(FileUtils.getUserDirResPath(File.separator+"res"+File.separator+"fonts"+File.separator+"icomoon.svg"));
//            File icomoon = new File(FileUtils.getUserDirResPath(File.separator+"res"+File.separator+"fonts"+File.separator+"icomoon.svg"));
            SVGGlyphLoader.loadGlyphsFont(new FileInputStream(resIcomoon), resIcomoon.getName());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public SVGGlyph getPlaySVG(int size, Paint paint) {
        return getSVG("play-circle-o", size, paint);
    }

    public SVGGlyph getMinusSquareSVG(int size, Paint paint) {
        return getSVG("minus-square", size, paint);
    }

    public SVGGlyph getPlusSquareSVG(int size, Paint paint) {
        return getSVG("plus-square", size, paint);
    }

    public SVGGlyph getMagnetSVG(int size, Paint paint) {
        return getSVG("magnet", size, paint);
    }

    public SVGGlyph getPauseSVG(int size, Paint paint) {
        return getSVG("pause", size, paint);
    }

    public SVGGlyph getRefreshSVG(int size, Paint paint) {
        return getSVG("spinner9", size, paint);
    }

    public SVGGlyph getClock1SVG(int size, Paint paint) {
        return getSVG("clock", size, paint);
    }

    public SVGGlyph getClock2SVG(int size, Paint paint) {
        return getSVG("clock2", size, paint);
    }

    public SVGGlyph getClockOSVG(int size, Paint paint) {
        return getSVG("clock-o", size, paint);
    }

    public SVGGlyph getEditSVG(int size, Paint paint) {
        return getSVG("pencil", size, paint);
    }

    public SVGGlyph getAdjustSVG(int size, Paint paint) {
        return getSVG("adjust", size, paint);
    }

    public SVGGlyph getCaretDownSVG(int size, Paint paint) {
        return getSVG("caret-down", size, paint);
    }

    public SVGGlyph getFolderSVG(int size, Paint paint) {
        return getSVG("folder-o", size, paint);
    }

    public SVGGlyph getImageSVG(int size, Paint paint) {
        return getSVG("image2", size, paint);
    }

    public SVGGlyph getFileSVG(int size, Paint paint) {
        return getSVG("file-text-o", size, paint);
    }

    public SVGGlyph getEyeSVG(int size, Paint paint) {
        return getSVG("eye", size, paint);
    }

    public SVGGlyph getSaveSVG(int size, Paint paint) {
        return getSVG("save", size, paint);
    }

    public SVGGlyph getOpenFolderSVG(int size, Paint paint) {
        return getSVG("folder-open2", size, paint);
    }

    public SVGGlyph getPackageSVG(int size, Paint paint) {
        return getSVG("hammer2", size, paint);
    }

    public SVGGlyph getWidthDpiSVG(int size, Paint paint) {
        return getSVG("arrows-h", size, paint);
    }

    public SVGGlyph getHeightDpiSVG(int size, Paint paint) {
        return getSVG("arrows-v", size, paint);
    }

    public SVGGlyph getGroupXMLSVG(int size, Paint paint) {
        return getSVG("list", size, paint);
    }

    public SVGGlyph getButtonXMLSVG(int size, Paint paint) {
        return getSVG("bold", size, paint);
    }

    public SVGGlyph getTextXMLSVG(int size, Paint paint) {
        return getSVG("font", size, paint);
    }

    public SVGGlyph getVarXMLSVG(int size, Paint paint) {
        return getSVG("vine", size, paint);
    }

    public SVGGlyph getLockcreenXMLSVG(int size, Paint paint) {
        return getSVG("filter", size, paint);
    }

    public SVGGlyph getSliderXMLSVG(int size, Paint paint) {
        return getSVG("equalizer", size, paint);
    }


    public SVGGlyph getOtherXMLSVG(int size, Paint paint) {
        return getSVG("circle-o", size, paint);
    }

    public SVGGlyph getUnlockerXMLSVG(int size, Paint paint) {
        return getSVG("unlock", size, paint);
    }

    public SVGGlyph getTimeXMLSVG(int size, Paint paint) {
        return getSVG("tumblr-square", size, paint);
    }

    public SVGGlyph getDownSVG(int size, Paint paint) {
        return getSVG("angle-down", size, paint);
    }

    public SVGGlyph getUpSVG(int size, Paint paint) {
        return getSVG("angle-up", size, paint);
    }

    public SVGGlyph getAddSVG(int size, Paint paint) {
        return getSVG("plus-circle", size, paint);
    }

    public SVGGlyph getTrashSVG(int size, Paint paint) {
        return getSVG("trash", size, paint);
    }
    public SVGGlyph getTrashOSVG(int size, Paint paint) {
        return getSVG("trash-o", size, paint);
    }

    public SVGGlyph getShrink2SVG(int size, Paint paint) {
        return getSVG("shrink2", size, paint);
    }


    private SVGGlyph getSVG(String name, int size, Paint paint) {
        SVGGlyph svgGlyph = null;
        try {
            svgGlyph = SVGGlyphLoader.getIcoMoonGlyph("icomoon.svg." + name);
            svgGlyph.setFill(paint);
            svgGlyph.setSize(size);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return svgGlyph;
    }
}
